<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>线路管理</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" th:href="@{/css/font.css}">
        <link rel="stylesheet" th:href="@{/css/xadmin.css}">
        <link rel="stylesheet" href="../lib/layui/css/layui.css" media="all">
        <script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
        <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
        <script src="../js/jquery.min.js" charset="utf-8"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-card-header">线路管理</div>
                <form class="layui-form">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">线路编号：</label>
                            <div class="layui-input-inline">
                                <input class="layui-input" name="lineCode" id="lineCode" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">线路状态：</label>
                            <div class="layui-input-inline">
                                <select id="getSystemconfig" lay-filter="xmFilter" name="Systemconfig">
                                    <option value="">--请选择--</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" >
                            <button class="layui-btn" lay-submit="" lay-filter="search">查询</button>
                        </div>
                    </div>
                </form>
                <div class="layui-col-md12">
                    <div class="layui-card" style="padding-bottom: 1px">
                        <div class="layui-card-body ">
                            <table class="layui-table" lay-data="{url:'/line/getLine',page:true,limit:5,id:'line'}" lay-filter="demo">
                                <thead>
                                    <tr>
                                        <th lay-data="{field:'lineCode', width:100, sort: true}">线路编号</th>
                                        <th lay-data="{field:'lineName', width:125}">线路名称</th>
                                        <th lay-data="{field:'startPoleCode', width:100}">起始杆号</th>
                                        <th lay-data="{field:'endPoleCode', width:100}">终止杆号</th>
                                        <th lay-data="{field:'towerBaseNum', width:125}">塔基数</th>
                                        <th lay-data="{field:'runningStatusName', width:100}">运行状态</th>
                                        <th lay-data="{field:'isStartStr', width:100}">启用状态</th>
                                        <th lay-data="{fixed: 'right', width:225, align:'center', toolbar: '#barDemo'}">操作</th>
                                    </tr>
                                </thead>
                            </table>
                            <script type="text/html" id="barDemo">
                                {{# if(d.isStart==1){ }}
                                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">停用</a>
                                {{# } }}
                                {{# if(d.isStart==0){ }}
                                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">启用</a>
                                {{# } }}
                                <a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
                                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                            </script>
                        </div>
                        <div style="margin-left:15px">
                            <div class="layui-form-item">
                                <a>
                                    <button id="add" onclick="" class="layui-btn" style="margin-right:200px;background-color: #93D1FF">
                                        <i class="layui-icon" onclick="window.location.href='edit'" >添加线路</i>
                                    </button>
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script>
            layui.use(['table', 'layer', 'form'], function () {

                var form=layui.form;
                var table=layui.table;
                //获取路线状态
                $.ajax({
                    url: '/line/getSystemconfig',
                    dataType: 'json',
                    type: 'get',
                    success: function (data) {
                        $.each(data, function (index, c) {
                            $('#getSystemconfig').append(new Option(c.configValueName,c.configValueId));
                        });
                        layui.form.render("select");
                    }
                });
                //线路编号+线路状态查询
                form.on('submit(search)', function(data){
                    var formData=data.field;
                    var lineCode=formData.lineCode;
                    var systemConfig=formData.Systemconfig;
                    url=formData.url;
                    icon=formData.icon;
                    parent_id=formData.parent_id;
                    table.reload('line', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        , where: {
                            lineCode: lineCode,
                            systemConfig: systemConfig
                        }
                        , url: '/line/getLine'
                        , method: 'post'
                    });
                    return false;
                });
                var layer=layui.layer;
                //监听工具条
                table.on('tool(demo)', function(obj){
                    var data = obj.data;
                    if(obj.event === 'detail'){
                        layer.confirm('确认修改启用状态？', function(index){
                            $.ajax({
                                type:"POST",
                                url:'/line/upIsStart?id='+data.id+"&isStart="+data.isStart,
                                async: false,
                                contentType:'application/json;charset=UTF-8',
                                dataType:'json',
                                success:function(data){
                                    if(data){
                                        layer.close(index);
                                        layer.msg('修改成功');
                                        table.reload("line");
                                    }else{
                                        layer.msg('修改失败');
                                    }
                                },
                                error:function () {
                                }
                            });
                        });
                    } else if(obj.event === 'del'){
                        layer.confirm('确认删除？', function(index){
                            $.ajax({
                                type:"POST",
                                url:'/line/del?id='+data.id,
                                async: false,
                                contentType:'application/json;charset=UTF-8',
                                dataType:'json',
                                success:function(data){
                                    if(data){
                                        obj.del();
                                        layer.close(index);
                                        layer.msg('删除成功');
                                    }else{
                                        layer.msg('删除失败');
                                    }
                                },
                                error:function () {
                                }
                            });
                        });
                    } else if(obj.event === 'edit'){
                        window.location.href='/line/edit?id='+data.id;
                    }
                });


            });


        </script>
    </body>
</html>